package org.potomak.patientmanager.tools;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author mobile
 */
public class PasswordMD5 {

    public static String passwordMD5(String password) {

        byte[] passwordBytes = password.getBytes();
        StringBuffer hexString = new StringBuffer();

        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(passwordBytes);
            byte messageDigest[] = algorithm.digest();

            for (int i = 0; i < messageDigest.length; i++) {
                if ((0xFF & messageDigest[i]) < 16) {
                    hexString.append("0");
                }
                hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            }
        } catch (NoSuchAlgorithmException nsae) {
            nsae.printStackTrace();
        }

        return hexString.toString();
    }
}
